{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "da5c8756",
   "metadata": {},
   "source": [
    "# This is a script to detect the object and calculate the x,y,z position with the camera."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e305f39b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting RealSense camera...\n",
      "Waiting for camera to stabilize...\n",
      "Taking picture...\n",
      "Color image saved as: realsense.jpg\n",
      "Raw depth data saved as: realsense_depth_raw.npy\n",
      "Camera intrinsics saved as: camera_intrinsics.npy\n",
      "Depth visualization saved as: realsense_depth.png\n",
      "Displaying images...\n",
      "Press any key to close the image windows...\n",
      "Taking picture...\n",
      "Color image saved as: realsense.jpg\n",
      "Raw depth data saved as: realsense_depth_raw.npy\n",
      "Camera intrinsics saved as: camera_intrinsics.npy\n",
      "Depth visualization saved as: realsense_depth.png\n",
      "Displaying images...\n",
      "Press any key to close the image windows...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pictures captured and saved successfully!\n",
      "Camera pipeline stopped.\n",
      "Camera pipeline stopped.\n"
     ]
    }
   ],
   "source": [
    "import pyrealsense2 as rs\n",
    "import numpy as np\n",
    "import cv2\n",
    "import os\n",
    "from datetime import datetime\n",
    "\n",
    "# Configure depth and color streams\n",
    "pipeline = rs.pipeline()\n",
    "config = rs.config()\n",
    "\n",
    "# Get device product line for setting a supporting resolution\n",
    "pipeline_wrapper = rs.pipeline_wrapper(pipeline)\n",
    "pipeline_profile = config.resolve(pipeline_wrapper)\n",
    "device = pipeline_profile.get_device()\n",
    "device_product_line = str(device.get_info(rs.camera_info.product_line))\n",
    "\n",
    "found_rgb = False\n",
    "for s in device.sensors:\n",
    "    if s.get_info(rs.camera_info.name) == 'RGB Camera':\n",
    "        found_rgb = True\n",
    "        break\n",
    "if not found_rgb:\n",
    "    print(\"The demo requires Depth camera with Color sensor\")\n",
    "    exit(0)\n",
    "\n",
    "# Configure streams\n",
    "config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)\n",
    "if device_product_line == 'L500':\n",
    "    config.enable_stream(rs.stream.color, 960, 540, rs.format.bgr8, 30)\n",
    "else:\n",
    "    config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)\n",
    "\n",
    "# Start streaming\n",
    "print(\"Starting RealSense camera...\")\n",
    "pipeline.start(config)\n",
    "\n",
    "try:\n",
    "    # Wait a bit for the camera to stabilize\n",
    "    print(\"Waiting for camera to stabilize...\")\n",
    "    for i in range(30):\n",
    "        frames = pipeline.wait_for_frames()\n",
    "    \n",
    "    # Take a picture\n",
    "    print(\"Taking picture...\")\n",
    "    frames = pipeline.wait_for_frames()\n",
    "    depth_frame = frames.get_depth_frame()\n",
    "    color_frame = frames.get_color_frame()\n",
    "    \n",
    "    if not depth_frame or not color_frame:\n",
    "        print(\"Error: Could not get frames\")\n",
    "    else:\n",
    "        # Convert images to numpy arrays\n",
    "        depth_image = np.asanyarray(depth_frame.get_data())\n",
    "        color_image = np.asanyarray(color_frame.get_data())\n",
    "        \n",
    "        # Save the color image\n",
    "        cv2.imwrite(\"realsense.jpg\", color_image)\n",
    "        print(\"Color image saved as: realsense.jpg\")\n",
    "        \n",
    "        # Save raw depth data as numpy array for 3D calculations\n",
    "        np.save(\"realsense_depth_raw.npy\", depth_image)\n",
    "        print(\"Raw depth data saved as: realsense_depth_raw.npy\")\n",
    "        \n",
    "        # Get and save camera intrinsics\n",
    "        depth_intrin = depth_frame.profile.as_video_stream_profile().intrinsics\n",
    "        intrinsics_data = {\n",
    "            'width': depth_intrin.width,\n",
    "            'height': depth_intrin.height,\n",
    "            'ppx': depth_intrin.ppx,\n",
    "            'ppy': depth_intrin.ppy,\n",
    "            'fx': depth_intrin.fx,\n",
    "            'fy': depth_intrin.fy,\n",
    "            'model': depth_intrin.model,\n",
    "            'coeffs': depth_intrin.coeffs\n",
    "        }\n",
    "        np.save(\"camera_intrinsics.npy\", intrinsics_data)\n",
    "        print(\"Camera intrinsics saved as: camera_intrinsics.npy\")\n",
    "        \n",
    "        # Apply colormap on depth image for visualization\n",
    "        depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)\n",
    "        cv2.imwrite(\"realsense_depth.png\", depth_colormap)\n",
    "        print(\"Depth visualization saved as: realsense_depth.png\")\n",
    "        \n",
    "        # Display the images\n",
    "        print(\"Displaying images...\")\n",
    "        cv2.imshow('RealSense Color', color_image)\n",
    "        cv2.imshow('RealSense Depth', depth_colormap)\n",
    "        \n",
    "        print(\"Press any key to close the image windows...\")\n",
    "        cv2.waitKey(0)\n",
    "        cv2.destroyAllWindows()\n",
    "        \n",
    "        print(\"Pictures captured and saved successfully!\")\n",
    "\n",
    "finally:\n",
    "    # Stop streaming\n",
    "    pipeline.stop()\n",
    "    print(\"Camera pipeline stopped.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "456ed097",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Image loaded successfully from /home/robot1/JuliusWorkplace/Tongji_Intelligent_Systems_Lab/Teaching_Scripts/Realsense_for_CV/realsense.jpg\n",
      "\n",
      "\n",
      "0: 480x640 None141.8ms\n",
      "Speed: 4.1ms preprocess, 141.8ms inference, 9.4ms postprocess per image at shape (1, 3, 480, 640)\n",
      "0: 480x640 None141.8ms\n",
      "Speed: 4.1ms preprocess, 141.8ms inference, 9.4ms postprocess per image at shape (1, 3, 480, 640)\n",
      "Found 2 detections\n",
      "Detection 1:\n",
      "  Class: block\n",
      "  Confidence: 0.684\n",
      "  Center pixel: (330, 280)\n",
      "  3D Position (meters):\n",
      "    X: 0.012 (left(-)/right(+))\n",
      "    Y: 0.054 (up(-)/down(+))\n",
      "    Z: 0.517 distance in z axis from camera\n",
      "  Distance from camera: 0.517 meters\n",
      "--------------------------------------------------\n",
      "Detection result saved as: /home/robot1/JuliusWorkplace/Tongji_Intelligent_Systems_Lab/Teaching_Scripts/Realsense_for_CV/detection_result.jpg\n",
      "Press any key to close the detection window...\n",
      "Found 2 detections\n",
      "Detection 1:\n",
      "  Class: block\n",
      "  Confidence: 0.684\n",
      "  Center pixel: (330, 280)\n",
      "  3D Position (meters):\n",
      "    X: 0.012 (left(-)/right(+))\n",
      "    Y: 0.054 (up(-)/down(+))\n",
      "    Z: 0.517 distance in z axis from camera\n",
      "  Distance from camera: 0.517 meters\n",
      "--------------------------------------------------\n",
      "Detection result saved as: /home/robot1/JuliusWorkplace/Tongji_Intelligent_Systems_Lab/Teaching_Scripts/Realsense_for_CV/detection_result.jpg\n",
      "Press any key to close the detection window...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n",
      "QObject::moveToThread: Current thread (0x36852f0) is not the object's thread (0x36cf5e0).\n",
      "Cannot move to target thread (0x36852f0)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from ultralytics import YOLO\n",
    "import cv2\n",
    "import numpy as np\n",
    "import pyrealsense2 as rs\n",
    "\n",
    "# Load the trained YOLOv8-OBB model\n",
    "model_path = \"/home/robot1/JuliusWorkplace/runs_obb/yolov8_obb_local/weights/best.pt\"\n",
    "model = YOLO(model_path)\n",
    "\n",
    "# Load the captured images and camera data\n",
    "image_path = \"/home/robot1/JuliusWorkplace/Tongji_Intelligent_Systems_Lab/Teaching_Scripts/Realsense_for_CV/realsense.jpg\"\n",
    "color_image = cv2.imread(image_path)\n",
    "\n",
    "# Load raw depth data and camera intrinsics\n",
    "depth_raw = np.load(\"realsense_depth_raw.npy\")\n",
    "intrinsics_data = np.load(\"camera_intrinsics.npy\", allow_pickle=True).item()\n",
    "\n",
    "# Recreate intrinsics object\n",
    "intrinsics = rs.intrinsics()\n",
    "intrinsics.width = intrinsics_data['width']\n",
    "intrinsics.height = intrinsics_data['height']\n",
    "intrinsics.ppx = intrinsics_data['ppx']\n",
    "intrinsics.ppy = intrinsics_data['ppy']\n",
    "intrinsics.fx = intrinsics_data['fx']\n",
    "intrinsics.fy = intrinsics_data['fy']\n",
    "intrinsics.model = intrinsics_data['model']\n",
    "intrinsics.coeffs = intrinsics_data['coeffs']\n",
    "\n",
    "if color_image is None:\n",
    "    print(f\"Error: Could not load image from {image_path}\")\n",
    "else:\n",
    "    print(f\"Image loaded successfully from {image_path}\")\n",
    "    \n",
    "    # Run YOLOv8-OBB detection\n",
    "    results = model(color_image)\n",
    "    \n",
    "    # Process detection results\n",
    "    for r in results:\n",
    "        # Get oriented bounding boxes\n",
    "        if r.obb is not None and len(r.obb) > 0:\n",
    "            boxes = r.obb.xyxyxyxy.cpu().numpy()  # Oriented bounding box coordinates\n",
    "            conf = r.obb.conf.cpu().numpy()       # Confidence scores\n",
    "            cls = r.obb.cls.cpu().numpy()         # Class indices\n",
    "            \n",
    "            # Draw results\n",
    "            annotated_image = color_image.copy()\n",
    "            \n",
    "            print(f\"Found {len(boxes)} detections\")\n",
    "            \n",
    "            for i, (box, confidence, class_id) in enumerate(zip(boxes, conf, cls)):\n",
    "                if confidence > 0.3:  # Confidence threshold\n",
    "                    # Get class name\n",
    "                    class_name = model.names[int(class_id)]\n",
    "                    \n",
    "                    # Calculate center of oriented bounding box\n",
    "                    center_x = int(np.mean(box[:, 0]))\n",
    "                    center_y = int(np.mean(box[:, 1]))\n",
    "                    \n",
    "                    # Get depth value at center point (in millimeters)\n",
    "                    depth_value = depth_raw[center_y, center_x]\n",
    "                    \n",
    "                    if depth_value > 0:  # Valid depth reading\n",
    "                        # Convert pixel coordinates to 3D coordinates\n",
    "                        point_3d = rs.rs2_deproject_pixel_to_point(\n",
    "                            intrinsics, [center_x, center_y], depth_value\n",
    "                        )\n",
    "                        \n",
    "                        # Convert to meters\n",
    "                        x_distance = point_3d[0] / 1000.0  # X: left(-)/right(+)\n",
    "                        y_distance = point_3d[1] / 1000.0  # Y: up(-)/down(+)\n",
    "                        z_distance = point_3d[2] / 1000.0  # Z: distance from camera\n",
    "                        \n",
    "                        # Draw oriented bounding box\n",
    "                        box_int = box.astype(int)\n",
    "                        cv2.polylines(annotated_image, [box_int], True, (0, 255, 0), 2)\n",
    "                        \n",
    "                        # Draw center point\n",
    "                        cv2.circle(annotated_image, (center_x, center_y), 5, (0, 0, 255), -1)\n",
    "                        \n",
    "                        # Prepare labels with 3D coordinates\n",
    "                        label = f\"{class_name}: {confidence:.2f}\"\n",
    "                        distance_label = f\"XYZ: ({x_distance:.3f}, {y_distance:.3f}, {z_distance:.3f})m\"\n",
    "                        \n",
    "                        # Draw labels\n",
    "                        cv2.putText(annotated_image, label, \n",
    "                                   (center_x - 80, center_y - 30), \n",
    "                                   cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2)\n",
    "                        cv2.putText(annotated_image, distance_label, \n",
    "                                   (center_x - 80, center_y - 10), \n",
    "                                   cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 0), 2)\n",
    "                        \n",
    "                        # Print detection results\n",
    "                        print(f\"Detection {i+1}:\")\n",
    "                        print(f\"  Class: {class_name}\")\n",
    "                        print(f\"  Confidence: {confidence:.3f}\")\n",
    "                        print(f\"  Center pixel: ({center_x}, {center_y})\")\n",
    "                        print(f\"  3D Position (meters):\")\n",
    "                        print(f\"    X: {x_distance:.3f} (left(-)/right(+))\")\n",
    "                        print(f\"    Y: {y_distance:.3f} (up(-)/down(+))\")\n",
    "                        print(f\"    Z: {z_distance:.3f} distance in z axis from camera\")\n",
    "                        print(f\"  Distance from camera: {z_distance:.3f} meters\")\n",
    "                        print(\"-\" * 50)\n",
    "                    \n",
    "                    else:\n",
    "                        print(f\"Detected {class_name} but no valid depth data at center point\")\n",
    "                        # Still draw the detection without distance info\n",
    "                        box_int = box.astype(int)\n",
    "                        cv2.polylines(annotated_image, [box_int], True, (0, 255, 0), 2)\n",
    "                        cv2.circle(annotated_image, (center_x, center_y), 5, (0, 0, 255), -1)\n",
    "                        \n",
    "                        label = f\"{class_name}: {confidence:.2f}\"\n",
    "                        cv2.putText(annotated_image, label, \n",
    "                                   (center_x - 50, center_y - 30), \n",
    "                                   cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2)\n",
    "            \n",
    "            # Save and display annotated image\n",
    "            output_path = \"/home/robot1/JuliusWorkplace/Tongji_Intelligent_Systems_Lab/Teaching_Scripts/Realsense_for_CV/detection_result.jpg\"\n",
    "            cv2.imwrite(output_path, annotated_image)\n",
    "            print(f\"Detection result saved as: {output_path}\")\n",
    "            \n",
    "            # Display the result\n",
    "            cv2.imshow('YOLOv8-OBB Detection with 3D Coordinates', annotated_image)\n",
    "            print(\"Press any key to close the detection window...\")\n",
    "            cv2.waitKey(0)\n",
    "            cv2.destroyAllWindows()\n",
    "            \n",
    "        else:\n",
    "            print(\"No objects detected in the image\")\n",
    "    \n",
    "    print(\"Detection completed.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "998c4f2c",
   "metadata": {},
   "outputs": [
    {
     "ename": "RuntimeError",
     "evalue": "libfranka: Connection to FCI refused. Please install FCI feature or enable FCI mode in Desk.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mRuntimeError\u001b[0m                              Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[14], line 4\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpanda_py\u001b[39;00m\n\u001b[1;32m      2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpanda_py\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m libfranka\n\u001b[0;32m----> 4\u001b[0m panda \u001b[38;5;241m=\u001b[39m panda_py\u001b[38;5;241m.\u001b[39mPanda(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m172.16.0.2\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m      5\u001b[0m hand \u001b[38;5;241m=\u001b[39m libfranka\u001b[38;5;241m.\u001b[39mGripper(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m172.16.0.2\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[0;31mRuntimeError\u001b[0m: libfranka: Connection to FCI refused. Please install FCI feature or enable FCI mode in Desk."
     ]
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
      "\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
      "\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
      "\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
     ]
    }
   ],
   "source": [
    "import panda_py\n",
    "from panda_py import libfranka\n",
    "\n",
    "panda = panda_py.Panda(\"172.16.0.2\")\n",
    "hand = libfranka.Gripper(\"172.16.0.2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4c8b7a2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 9.99962515e-01  7.45188708e-03  4.29702466e-04  3.07542751e-01]\n",
      " [ 7.45296594e-03 -9.99959306e-01 -2.56631095e-03 -7.70888138e-04]\n",
      " [ 4.10561120e-04  2.56941731e-03 -9.99996615e-01  4.86115770e-01]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00  1.00000000e+00]]\n"
     ]
    }
   ],
   "source": [
    "print(panda.get_pose())  # Get the current pose of the robot arm"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
